import { fromJS } from "immutable"
import * as types from "./action-types"

const initData = fromJS({
    topicList: [],
    homeList: [],
    pages: 1,
    showScroll: false
})
export default (state = initData, action) => {
    switch (action.type) {
        case types.GET_HOME_TOPIC:
            return state.set("topicList", fromJS(action.data))
        case types.GET_HOME_LIST:
            return state.set("homeList", fromJS(action.data))
        case types.GET_LOAD_MORE:
            const page = state.get("pages");
            return state.merge({
                homeList: state.get("homeList").concat(action.data),
                pages: page + 1
            })
        case types.SET_HOME_SCROLL:
            return state.set("showScroll", action.data)
        default:
            return state;
    }
}